<!doctype html>
<html style='font-size:20px !important'>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
<title>基础章节-05-企业数据库存储服务</title><style type='text/css'>html {overflow-x: initial !important;}:root { --bg-color:#ffffff; --text-color:#333333; --select-text-bg-color:#B5D6FC; --select-text-font-color:auto; --monospace:"Lucida Console",Consolas,"Courier",monospace; }
html { font-size: 14px; background-color: var(--bg-color); color: var(--text-color); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { margin: 0px; padding: 0px; height: auto; bottom: 0px; top: 0px; left: 0px; right: 0px; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; tab-size: 4; }
iframe { margin: auto; }
a.url { word-break: break-all; }
a:active, a:hover { outline: 0px; }
.in-text-selection, ::selection { text-shadow: none; background: var(--select-text-bg-color); color: var(--select-text-font-color); }
#write { margin: 0px auto; height: auto; width: inherit; word-break: normal; overflow-wrap: break-word; position: relative; white-space: normal; overflow-x: visible; padding-top: 40px; }
#write.first-line-indent p { text-indent: 2em; }
#write.first-line-indent li p, #write.first-line-indent p * { text-indent: 0px; }
#write.first-line-indent li { margin-left: 2em; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
.typora-export .footnote-line, .typora-export li, .typora-export p { white-space: pre-wrap; }
@media screen and (max-width: 500px) {
  body.typora-export { padding-left: 0px; padding-right: 0px; }
  #write { padding-left: 20px; padding-right: 20px; }
  .CodeMirror-sizer { margin-left: 0px !important; }
  .CodeMirror-gutters { display: none !important; }
}
#write li > figure:last-child { margin-bottom: 0.5rem; }
#write ol, #write ul { position: relative; }
img { max-width: 100%; vertical-align: middle; }
button, input, select, textarea { color: inherit; font: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p { position: relative; }
p { line-height: inherit; }
h1, h2, h3, h4, h5, h6 { break-after: avoid-page; break-inside: avoid; orphans: 2; }
p { orphans: 4; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
.md-math-block, .md-rawblock, h1, h2, h3, h4, h5, h6, p { margin-top: 1rem; margin-bottom: 1rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; cursor: pointer; }
sup.md-footnote a, sup.md-footnote a:hover { color: inherit; text-transform: inherit; text-decoration: inherit; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
figure { overflow-x: auto; margin: 1.2em 0px; max-width: calc(100% + 16px); padding: 0px; }
figure > table { margin: 0px !important; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; text-align: left; }
table.md-table td { min-width: 32px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; }
.CodeMirror-linenumber { user-select: none; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
#write pre { white-space: pre-wrap; }
#write.fences-no-line-wrapping pre { white-space: pre; }
#write pre.ty-contain-cm { white-space: normal; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
#write .md-fences.mock-cm { white-space: pre-wrap; }
.md-fences.md-fences-with-lineno { padding-left: 0px; }
#write.fences-no-line-wrapping .md-fences.mock-cm { white-space: pre; overflow-x: auto; }
.md-fences.mock-cm.md-fences-with-lineno { padding-left: 8px; }
.CodeMirror-line, twitterwidget { break-inside: avoid; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background: 0px 0px; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; direction: ltr; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child, li > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: normal; }
#write .footnote-line { white-space: pre-wrap; }
@media print {
  body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; }
  #write { margin-top: 0px; padding-top: 0px; border-color: transparent !important; }
  .typora-export * { -webkit-print-color-adjust: exact; }
  html.blink-to-pdf { font-size: 13px; }
  .typora-export #write { padding-left: 32px; padding-right: 32px; padding-bottom: 0px; break-after: avoid; }
  .typora-export #write::after { height: 0px; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > .md-image:only-child:not(.md-img-error) img, p > img:only-child { display: block; margin: auto; }
p > .md-image:only-child { display: inline-block; width: 100%; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.md-math-block { width: 100%; }
.md-math-block:not(:empty)::after { display: none; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); border: none; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-content::after, .md-toc::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-item a { text-decoration: none; }
.md-toc-inner:hover { text-decoration: underline; }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
  .md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
  .md-toc-h4 .md-toc-inner { margin-left: 5em; }
  .md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
  .md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, samp, tt { font-family: var(--monospace); }
kbd { margin: 0px 0.1em; padding: 0.1em 0.6em; font-size: 0.8em; color: rgb(36, 39, 41); background: rgb(255, 255, 255); border: 1px solid rgb(173, 179, 185); border-radius: 3px; box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset; white-space: nowrap; vertical-align: middle; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: var(--monospace); }
code { text-align: left; vertical-align: initial; }
a.md-print-anchor { white-space: pre !important; border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.html-for-mac .inline-math-svg .MathJax_SVG { vertical-align: 0.2px; }
.md-math-block .MathJax_SVG_Display { text-align: center; margin: 0px; position: relative; text-indent: 0px; max-width: none; max-height: none; min-height: 0px; min-width: 100%; width: auto; overflow-y: hidden; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: var(--monospace); }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: 400; line-height: normal; zoom: 90%; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { transition: none 0s ease 0s; }
.MathJax_SVG_Display svg { vertical-align: middle !important; margin-bottom: 0px !important; margin-top: 0px !important; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg { max-width: 100%; }
[lang="mermaid"] svg, [lang="flow"] svg { max-width: 100%; height: auto; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }
video { max-width: 100%; display: block; margin: 0px auto; }
iframe { max-width: 100%; width: 100%; border: none; }
.highlight td, .highlight tr { border: 0px; }


.CodeMirror { height: auto; }
.CodeMirror.cm-s-inner { background: inherit; }
.CodeMirror-scroll { overflow: auto hidden; z-index: 3; }
.CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler { background-color: rgb(255, 255, 255); }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background: inherit; white-space: nowrap; }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: rgb(0, 0, 0); }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-property { color: rgb(0, 0, 0); }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: rgb(0, 0, 255); }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: 700; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: red; }
.cm-invalidchar { color: red; }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { height: 100%; outline: 0px; position: relative; box-sizing: content-box; background: inherit; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar { position: absolute; z-index: 6; display: none; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow: hidden; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow: hidden; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 30px; z-index: 3; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: 0px 0px !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0px; bottom: 0px; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: 0px 0px; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; overflow-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { overflow-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
@media print {
  .CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}


:root { --side-bar-bg-color: #fff; --control-text-color: #777; --active-file-border-color: var(--drake-accent); --drake-accent: #e95f59; --drake-highlight: #d63200; }
html { font-size: 16px; }
body { font-family: "Source Han Sans SC", sans-serif; color: rgb(85, 85, 85); -webkit-font-smoothing: auto; line-height: 1.8rem; letter-spacing: 2px; margin: 0px; overflow-x: hidden; }
img { border-radius: 2px; }
#write { max-width: 1400px; margin: 0px auto; padding: 20px 30px 100px; }
#write p { line-height: 1.6rem; word-spacing: 0.05rem; }
#write > ul:first-child, #write > ol:first-child { margin-top: 30px; }
body > :first-child { margin-top: 0px !important; }
body > :last-child { margin-bottom: 0px !important; }
a { color: var(--drake-highlight); padding: 0px 2px; }
h1, h2, h3, h4, h5, h6 { position: relative; margin-top: 3rem; margin-bottom: 1rem; font-weight: bold; line-height: 1.4; cursor: text; color: rgb(39, 56, 73); }
h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor { text-decoration: none; }
h1 tt, h1 code { font-size: inherit !important; }
h2 tt, h2 code { font-size: inherit !important; }
h3 tt, h3 code { font-size: inherit !important; }
h4 tt, h4 code { font-size: inherit !important; }
h5 tt, h5 code { font-size: inherit !important; }
h6 tt, h6 code { font-size: inherit !important; }
h2 a, h3 a { color: rgb(52, 73, 94); }
h1 { padding-bottom: 0.4rem; font-size: 2.2rem; text-align: center; margin-top: 0px; line-height: 1.3; }
h2 { font-size: 1.75rem; line-height: 1.225; padding-bottom: 10px; margin-bottom: 2rem; border-bottom: 1px solid rgb(234, 236, 239); }
h3 { font-size: 1.4rem; line-height: 1.43; }
h4 { font-size: 1.2rem; }
h5 { font-size: 1rem; }
h6 { font-size: 1rem; color: rgb(119, 119, 119); }
p, blockquote, ul, ol, dl, table { margin: 0.8em 0px; }
li > ol, li > ul { margin: 0px; }
hr { height: 2px; padding: 0px; margin: 16px 0px; background-color: rgb(231, 231, 231); border: 0px none; overflow: hidden; box-sizing: content-box; }
body > h2:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child + h2 { margin-top: 0px; padding-top: 0px; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child { margin-top: 0px; padding-top: 0px; }
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 { margin-top: 0px; padding-top: 0px; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p { margin-top: 0px; }
li p.first { display: inline-block; }
ul, ol { padding-left: 30px; }
ul:first-child, ol:first-child { margin-top: 0px; }
ul:last-child, ol:last-child { margin-bottom: 0px; }
blockquote { color: rgb(48, 68, 85); border-radius: 2px; padding: 10px 16px; background-color: rgb(253, 239, 238); position: relative; border-left: none; }
blockquote::before { display: block; position: absolute; content: ""; width: 4px; left: 0px; top: 0px; height: 100%; background-color: var(--drake-accent); border-radius: 2px; }
table { padding: 0px; word-break: initial; }
table tr { border-top: 1px solid rgb(223, 226, 229); margin: 0px; padding: 0px; }
table tr:nth-child(2n), thead { background-color: rgb(250, 250, 250); }
table tr th { font-weight: bold; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: rgb(223, 226, 229); border-right-color: rgb(223, 226, 229); border-left-color: rgb(223, 226, 229); border-image: initial; border-bottom-style: initial; border-bottom-color: initial; text-align: left; margin: 0px; padding: 6px 13px; }
table tr td { border: 1px solid rgb(223, 226, 229); text-align: left; margin: 0px; padding: 6px 13px; }
table tr th:first-child, table tr td:first-child { margin-top: 0px; }
table tr th:last-child, table tr td:last-child { margin-bottom: 0px; }
#write em { padding: 0px 5px 0px 2px; }
#write table thead th { background-color: rgb(242, 242, 242); }
#write .CodeMirror-gutters { border-right: none; }
#write .md-fences { font-size: 1rem; border-radius: 2px; overflow-wrap: normal; background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); border: none; margin-left: 2px; margin-right: 2px; padding: 0.5rem !important; font-family: inherit !important; }
#write code, tt { margin: 0px 2px; border-radius: 2px; color: var(--drake-highlight); font-family: initial !important; }
#write mark { background-color: rgb(231, 236, 243); color: inherit; border-radius: 2px; padding: 2px; margin: 0px 2px; }
#write del { padding: 1px 2px; }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(34, 162, 201); }
.cm-s-inner .cm-string { color: rgb(34, 162, 201); }
.md-task-list-item > input { margin-left: -1.3em; }
@media print {
  html { font-size: 12px; }
  table, pre { break-inside: avoid; }
  pre { overflow-wrap: break-word; }
}
#write pre.md-meta-block { padding: 1rem; font-size: 85%; line-height: 1.45; background-color: rgb(247, 247, 247); border: 0px; border-radius: 2px; color: rgb(119, 119, 119); margin-top: 0px !important; }
.mathjax-block > .code-tooltip { bottom: 0.375rem; }
#write > h3.md-focus::before { left: -1.5625rem; top: 0.375rem; }
#write > h4.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h5.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h6.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
.md-image > .md-meta { border-radius: 2px; font-family: initial; padding: 2px 0px 0px 4px; color: inherit; }
.md-tag { color: inherit; }
.md-toc { margin-top: 20px; padding-bottom: 20px; }
.sidebar-tabs { border-bottom: none; }
#typora-quick-open { border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); }
.typora-quick-open-item { height: 48px; padding-left: 8px; padding-top: 4px; font-size: 1rem !important; }
#md-notification::before { top: 10px; }
.on-focus-mode blockquote { border-left-color: rgba(85, 85, 85, 0.12); }
header, .context-menu, .megamenu-content, footer { font-family: initial; }
.file-node-content:hover .file-node-icon, .file-node-content:hover .file-node-open-state { visibility: visible; }
.mac-seamless-mode #typora-sidebar { font-size: 1rem; background-color: var(--side-bar-bg-color); }
.md-lang { color: rgb(180, 101, 77); }
.html-for-mac .context-menu { --item-hover-bg-color: #E6F0FE; }
span.cm-comment { color: rgb(128, 128, 128) !important; }
.ty-quick-open-category.ty-has-prev .ty-quick-open-category-title { border-top: none; }
.file-list-item-summary { font-family: initial; }
#typora-quick-open-input { margin: 8px; box-shadow: none; border-radius: 2px; }
#typora-quick-open-input input { font-size: 1rem; box-shadow: none; padding-top: 2px; padding-left: 10px; padding-right: 10px; line-height: 32px; max-height: 32px; }
.modal-dialog#typora-quick-open { border-radius: 2px; }
.ty-quick-open-category-title { padding-left: 8px; color: rgb(190, 190, 190); }
.typora-quick-open-item-path { font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.outline-item { font-size: 1rem; }
.sidebar-tab { font-size: 1rem; }
#write .md-footnote { background-color: inherit; color: var(--drake-highlight); font-size: 0.9rem; border-radius: 0.9rem; padding-left: 0px; }
#write .md-footnote::before { content: "["; }
#write .md-footnote::after { content: "]"; }
.md-hover-tip .code-tooltip-content { border-radius: 2px; }
span.md-def-name { padding-right: 3ch; padding-left: 0px; position: relative; font-weight: normal; }
.footnotes { font-size: 1rem; font-weight: normal; color: rgb(48, 68, 85); position: relative; }
.code-tooltip-content .md-plain { font-size: 0.9rem; font-family: inherit; }
.code-tooltip-content code { padding: 0px 2px; font-family: inherit; color: rgb(255, 215, 96); background-color: inherit; }
.code-tooltip-content a { color: rgb(255, 215, 96); }
div.code-tooltip-content { box-shadow: rgba(0, 0, 0, 0.5) 0px 0px 8px; }
.footnotes { opacity: 1; }
.md-def-name::after { content: ". ^"; color: rgb(48, 68, 85); }
.md-def-footnote .md-def-name::before { content: ""; color: rgb(48, 68, 85); position: absolute; }
.md-def-name::before { content: ""; color: rgb(48, 68, 85); position: absolute; }
.CodeMirror-scroll::-webkit-scrollbar { display: none; }
.file-list-item-summary { font-size: 1em; }
.pin-outline #outline-content .outline-active strong, .pin-outline .outline-active { font-weight: 500; color: var(--drake-highlight); }
.file-list-item.active { border-left: 4px solid var(--drake-accent); }
.cm-s-inner.CodeMirror { background: rgb(43, 43, 43); color: rgb(169, 183, 198); }
.cm-s-inner span.cm-meta { color: rgb(187, 181, 41); }
.cm-s-inner span.cm-number { color: rgb(104, 151, 187); }
.cm-s-inner span.cm-keyword { color: rgb(204, 120, 50); }
.cm-s-inner span.cm-def { color: rgb(255, 215, 96); }
.cm-s-inner span.cm-variable { color: rgb(169, 183, 198); }
.cm-s-inner span.cm-variable-2 { color: rgb(169, 183, 198); }
.cm-s-inner span.cm-variable-3 { color: rgb(152, 118, 170); }
.cm-s-inner span.cm-type { color: rgb(170, 187, 204); }
.cm-s-inner span.cm-property { color: rgb(255, 198, 109); }
.cm-s-inner span.cm-operator { color: rgb(169, 183, 198); }
.cm-s-inner span.cm-string { color: rgb(106, 135, 89); }
.cm-s-inner span.cm-string-2 { color: rgb(106, 135, 89); }
.cm-s-inner span.cm-comment { color: rgb(97, 161, 81); }
.cm-s-inner span.cm-link { color: rgb(204, 120, 50); }
.cm-s-inner span.cm-atom { color: rgb(204, 120, 50); }
.cm-s-inner span.cm-error { color: rgb(188, 63, 60); }
.cm-s-inner span.cm-tag { color: rgb(232, 191, 106); }
.cm-s-inner span.cm-quote { color: rgb(166, 226, 46); }
.cm-s-inner span.cm-attribute { color: rgb(152, 118, 170); }
.cm-s-inner span.cm-qualifier { color: rgb(106, 135, 89); }
.cm-s-inner span.cm-bracket { color: rgb(232, 191, 106); }
.cm-s-inner span.cm-builtin { color: rgb(255, 158, 89); }
.cm-s-inner span.cm-special { color: rgb(255, 158, 89); }
.cm-s-inner span.cm-matchhighlight { color: rgb(255, 255, 255); background-color: rgba(50, 89, 48, 0.7); font-weight: normal; }
.cm-s-inner span.cm-searching { color: rgb(255, 255, 255); background-color: rgba(61, 115, 59, 0.7); font-weight: normal; }
.cm-s-inner .CodeMirror-cursor { border-left: 1px solid rgb(169, 183, 198); }
.cm-s-inner .CodeMirror-gutters { background: rgb(49, 51, 53); border-right: 1px solid rgb(49, 51, 53); }
.cm-s-inner .CodeMirror-guttermarker { color: rgb(255, 238, 128); }
.cm-s-inner .CodeMirror-guttermarker-subtle { color: rgb(208, 208, 208); }
.cm-s-inner .CodeMirrir-linenumber { color: rgb(96, 99, 102); }
.cm-s-inner .CodeMirror-matchingbracket { background-color: rgb(59, 81, 77); color: rgb(255, 239, 40) !important; }
.cm-s-inner .CodeMirror-selected { background: rgb(33, 66, 131) !important; }
.cm-s-inner .CodeMirror-selectedtext { background: rgb(33, 66, 131) !important; }
.cm-overlay.CodeMirror-selectedtext { background: rgb(181, 214, 252) !important; }
.cm-s-inner div.CodeMirror-cursor { border-left: 1px solid rgb(255, 255, 255); }

 .typora-export li, .typora-export p, .typora-export,  .footnote-line {white-space: normal;} 
</style>
</head>
<body class='typora-export os-windows' >
<div  id='write'  class = 'is-node'><h2><a name="%E5%9F%BA%E7%A1%80%E7%AB%A0%E8%8A%82-01-mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E4%B8%AD%E7%BA%A7%E8%AF%BE%E7%A8%8B" class="md-header-anchor"></a><span>基础章节-01-MySQL数据库服务中级课程</span></h2><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/%E5%8A%A8%E7%94%BB.gif' alt='' referrerPolicy='no-referrer' /></p><h3><a name="1.00-%E8%AF%BE%E7%A8%8B%E7%9F%A5%E8%AF%86%E7%AB%A0%E8%8A%82%E8%AF%B4%E6%98%8E" class="md-header-anchor"></a><span>1.00 课程知识章节说明</span></h3><p><span>目前在互联网的实际应用中，各个企业都会比较关注自身网站的数据信息，既要保证数据信息的安全性，同时也要保证数据存储读取效率</span></p><p><span>并且在特殊的场景下，还要对存储的数据信息进行检索和分析；因此数据库服务业务已经在各行各业应用非常的广泛</span></p><p><span>对于互联网领域的技术人员，对于数据库服务知识的掌握，也将是在求职时必备的技能，有些时候还会绝对入职的定级和薪资水平。</span></p><p>&nbsp;</p><h3><a name="1.07-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%B4%A2%E5%BC%95%E7%9F%A5%E8%AF%86" class="md-header-anchor"></a><span>1.07 数据库服务索引知识</span></h3><h4><a name="1.7.1-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5" class="md-header-anchor"></a><span>1.7.1 数据库索引相关概念</span></h4><ul><li><strong><span>索引概念介绍：</span></strong></li></ul><p><span>索引是数据库中用来提高数据读取性能的常用工具，所有mysql列类型都可以被索引，对相关列使用索引；</span></p><p><span>可以是提高select操作性能的最佳途径，可以尽可能快的锁定要查询数据的范围，从而达到加速查询的目的（减少IO消耗）；</span></p><p><span>一般索引设置都是应用在比较大的数据表上，比如百万级别、千万级别或亿级别的数据表中，从而完成一些针对性优化；</span></p><p><code>可以简单理解：数据库索引相当于书的目录，可以借助索引有针对的查看相应数据的信息，避免了全盘检索带来的工作量；</code></p><p><span>主要利用MySQL中的索引，可以快速锁定查询范围，mysql索引比较适合范围查找数据;</span></p><h4><a name="1.7.2-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E7%B1%BB%E5%9E%8B%E4%BB%8B%E7%BB%8D" class="md-header-anchor"></a><span>1.7.2 数据库索引类型介绍</span></h4><p><span>在MySQL数据库服务中，是有很多种索引类型的，但是比较常用的索引类型主要有：</span></p><figure><table><thead><tr><th><span>序号</span></th><th><span>类型</span></th><th><span>说明</span></th></tr></thead><tbody><tr><td><span>类型01</span></td><td><code>B+Tree</code></td><td><span>默认类型索引</span></td></tr><tr><td><span>类型02</span></td><td><span>Hash</span></td><td><span>算法类型索引</span></td></tr><tr><td><span>类型03</span></td><td><span>R+Tree</span></td><td><span>空间类型索引</span></td></tr><tr><td><span>类型04</span></td><td><span>Fulltext</span></td><td><span>全文类型索引</span></td></tr></tbody></table></figure><p>&nbsp;</p><p><strong><span>数据库数据查找算法演变：（B+Tree索引的由来）</span></strong></p><p><span>这个举个简单的例子，假设现在一个教室中有100来号人，这时可以派发礼品，通过礼品引诱这100人来报名学习xiaoQ老师课程；</span></p><p><span>比如礼品是学习课程的1000元代金券，现在把这1000元的代金券随机放到了1到100号盒子其中的一个里面，只有我知道放置的号码；</span></p><p><span>下面要求这100个人尽量快的猜到1~100号盒子里面，哪个有放置代金券的盒子，当然，我会给予一些合适的提示信息；</span></p><p><span>这时在场的100号人就需要想一些办法，在我合适的配合下，定位有代金券的盒子，想的办法就等价于是查找算法：</span></p><p><span>方法一：根据定位的盒子编号顺序，询问是与否，这种方式就可以理解为是遍历算法（全扫描），也可以理解为随机性算法；</span></p><p><span>方法二：根据定位的盒子编号比较，询问大于小，这种方式就可以理解为是二分算法（定范围），也可以理解为二叉树算法；</span></p><p><span>            看似这种二分算法比遍历算法，更加科学，但是如果代金券放在了第01号或第100号盒子里呢，或者二分节点两侧时呢？</span></p><p><span>            所以采用二分法依然会存在数据查询不平衡的问题。</span></p><p><span>通过以上两种算法的介绍，了解到都存在一些缺陷或问题，因此数据库在检索数据信息时，最终采用的算法是B+Tree，其中的B表示平衡</span></p><p><span>并且BTREE还可以细分为B-tree或B+tree，以及B++tree，其中的加号就是表示增强版或优化版的BTree；</span></p><p>&nbsp;</p><p><span>在讲解B+树之前先了解一下树的整体结构，无非就是二叉树、二叉搜索树、平衡二叉树，更高级一点的有红黑树、Btree、B+tree等；</span></p><p><span>而树的查找性能取决于树的高度，让树尽可能平衡是为了降低树的高度。</span></p><p><span>为什么MySQL会选用B+树的结构，可以先来看看其他的树形结构：</span></p><p><strong><span>二叉树：</span></strong></p><p><span>二叉树的每一个节点都只有两个子节点，当需要向其插入更多的数据的时候，就必须要增加树的高度，而增加树的高度会导致IO消耗大；</span></p><p><span>对于二叉树而言，它的查找操作的时间复杂度就是树的高度，树的高度越高查询性能就会随着数据的增多越来越低。</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1682955300451.png' alt='1682955300451' referrerPolicy='no-referrer' /></p><p><span>二叉树节点中，还存在非正常的倾斜（比如ID自增的情况）的二叉树，查询一次数据就相当于全表搜索，因此二叉树的查询性能特别差</span></p><p>&nbsp;</p><p><strong><span>红黑树：</span></strong></p><p><span>红黑树一种平衡二叉树，它复杂的定义和规则都是为了保证树的平衡性；</span></p><p>&nbsp;</p><p><strong><span>对于B++tree算法的底层算法逻辑理解：</span></strong></p><p><span>利用Btree算法还是快速锁定100个盒子中，有代金券的盒子编号，如下图所示：</span></p><ul><li><p><span>将需要存储的数据信息，均匀分配保存到对应页当中，最终数据信息的均匀存储（落盘）</span></p></li><li><p><span>根据页节点存储的数据信息，取出页节节点最小数据信息，并将每个叶节点最小数据信息进行汇总整合，生成相应内部节点数据；</span></p><p><span>实质上存储的是下层页节点的区间范围，以及与之对应的指针信息，最后构建出内部节点信息；</span></p></li><li><p><span>根据内部节点存储的数据信息，取出内部节点最小数据信息，并将每个内部节点最小值信息进行汇总整合，生成相应根节点数据；</span></p><p><span>根节点只能有占用一个页区域，如果一个页区域空间不够，需要进行内部节点层次扩展，但是尽量要保证层次越少越好；</span></p><p><span>实质上存储的是下层内部节点的区域范围，以及与之对应的指针信息，最后构建出独立且唯一的根节点信息；</span></p></li><li><p><span>整个树形结构，越向上节点存储数据的范围越大，然后依次再分发数据到下面的小范围，最终形成多叉树；</span></p><p><span>由于出现了多叉树，就表示全部数据分布在多个链表上，避免了单条链表存储数据，同时可以实现并发的访问数据</span></p></li><li><p><span>对于加号表示增强，其中增强表示在整个链表上，增加了同级相邻节点之间的双向指针，从而实现相邻节点相互跳转</span></p></li></ul><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1667936870251.png' alt='1667936870251' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>根据以上B+Tree的结构说明，假设现在需要查找54这个数据值信息所在的数据页：等值查询</span></strong></p><ul><li><span>根据定义查找的数值信息，首先在根节点中获取数值所在的区间范围和相应指针信息，从而找到下层对应的内部节点信息；</span></li><li><span>根据定义查找的数据信息，其次在枝节点中获取数值所在的区域范围和相应指针信息，从而找到下层对应的叶子节点信息；</span></li><li><span>根据定义查找的数据信息，最后在叶子节点中获取最终的数据信息，结果结合上图经历三步完成了数据查找（3*16=48kB）；</span></li></ul><p><span>在利用BTree查找数据信息时，会结合树形层次结构，来决定查询数据的步骤过程，并且理论上每个数据查找过程步骤相同；</span></p><blockquote><p><span>总结：B代表的平衡含义就是，每次查找数据消耗的IO数量是一致的，并且读取的页数量也是一致的，查找时间复杂度是一致的；</span></p></blockquote><p>&nbsp;</p><p><strong><span>根据以上B+Tree的结构说明，假设现在需要查找大于90这个数据值信息所在的数据页：不等值查询</span></strong></p><ul><li><span>根据定义查找的数值信息，首先在根节点中获取首个大于指定数值的区间范围和相应指针信息，从而找到下层对应的内部节点信息；</span></li><li><span>根据定义查找的数据信息，其次在枝节点中获取数值所在的区域范围和相应指针信息，并且结合双向指针进行预读；</span></li><li><span>根据定义查找的数据信息，最后在叶子节点中获取最终的数据信息，并且结合双向指针进行预读，查询其余大于90的数值；</span></li></ul><p><span>在利用BTree查找数据信息时，由于存在双向指针概念，可以避免重复从根查找问题，减少IO消耗，结合预读快速调取数据到内存中</span></p><blockquote><p><span>总结：在BTree中的双向链接增强特性和预读功能，可以根据簇（64page）读取数据，可以使数据信息的范围查找变得更加方便高效</span></p></blockquote><h4><a name="1.7.3-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E6%9E%84%E5%BB%BA%E8%BF%87%E7%A8%8B" class="md-header-anchor"></a><span>1.7.3 数据库索引构建过程</span></h4><p><span>数据库服务在进行BTree索引构建时，是比较重要的知识点，因为最终还是会应用BTree算法知识进行索引的构建，常用方法有：</span></p><p><strong><span>索引方式一：聚簇索引（集群索引/聚集索引）</span></strong></p><p><span>聚簇索引主要是：将多个簇（区-64个数据页-1M）聚集在一起就构成了所谓聚簇索引，也可以称之为主键索引；</span></p><p><span>聚簇索引作用是：用来组织存储表的数据行信息的，也可以理解为数据行信息都是按照聚簇索引结构进行存储的，即按区分配空间的；</span></p><p><span>聚簇索引的存储：聚簇是多个簇，簇是多个连续数据页(64个)，页是多个连续数据块(4个)，块是多个连续扇区(8个)；</span></p><blockquote><p><span>总结：利用聚簇索引可以实现从物理上或逻辑上，都能满足数据存储的连续性关系，方便进行数据查找的有序性IO；（IOT组织表）</span></p></blockquote><p>&nbsp;</p><p><span>聚簇索引的构建方式：</span></p><ul><li><span>数据表创建时，显示的构建了主键信息（pk），主键（pk）就是聚簇索引；</span></li><li><span>数据表创建时，没有显示的构建主键信息时，会将第一个不为空的UK的列做为聚簇索引；</span></li><li><span>数据表创建时，以上条件都不符合时，生成一个6字节的隐藏列作为聚簇索引；</span></li></ul><p><span>结合下图信息，可以看出聚簇索引组织存储数据过程与加速查询过程原理：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668072355146.png' alt='1668072355146' referrerPolicy='no-referrer' /></p><p><span>以上图信息为例，若显示创建ID列为pk自增列：</span></p><p><span>① 按照ID逻辑顺序，在同一个区中连续的数据页上，有序存储数据行；</span></p><p><span>② 数据行所在的数据页，作为聚簇索引的叶子节点（叶子节点就是所有数据行）；</span></p><p><span>③ 叶子节点构建完后，可以构建no-left（支节点），用于保存的是leaf节点中的ID范围和指针信息；</span></p><p><span>④ 支节点构建完后，可以构建root（根节点），用于保存的是no-leaf节点中的ID范围和指针信息；</span></p><p><span>⑤ 并且leaf节点和no-leaf相邻数据页之间都具有双向指针，从而加速数据的范围查找；</span></p><p>&nbsp;</p><p><strong><span>索引方式二：辅助索引</span></strong></p><p><span>辅助索引主要是：主要用于辅助聚簇索引查询的索引，一般按照业务查找条件，建立合理的索引信息，也可以称之为一般索引；</span></p><p><span>辅助索引作用是：主要是将需要查询的列信息可以和聚合索引信息建立有效的关联，从而使数据查询过程更高效，节省IO和CPU消耗</span></p><p><span>辅助索引的存储：调取需要建立的辅助索引列信息，并加上相应主键列的所有信息，存储在特定的数据页中；</span></p><blockquote><p><span>总结：利用辅助索引与聚合索引建立的关联，先经过辅助索引的查询获取对应聚簇索引，在经过聚簇索引回表查询获取详细数据；</span></p></blockquote><p>&nbsp;</p><p><span>辅助索引的构建方式：</span></p><ul><li><span>数据表创建时，显示的构建了一般索引信息（mul），一般索引信息（mul）就是辅助索引；</span></li><li><span>数据表创建时，没有显示的构建一般索引信息时，在查询检索指定数据信息，会进行全表扫描查找数据；</span></li></ul><p><span>结合下图信息，可以看出辅助索引组织存储数据过程与加速查询过程原理：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668091064864.png' alt='1668091064864' referrerPolicy='no-referrer' /></p><p><span>以上图信息为例，若显示创建name列为mul查询列：</span></p><p><span>① 调取需要建立的辅助索引列信息，并加上相应主键列的所有信息，存储在特定的内存区域中；</span></p><p><span>② 根据调取的辅助索引列信息，进行字符的顺序排序，便于形成范围查询的区间，并将排序后的数据信息存储在特定数据页中；</span></p><p><span>③ 叶子节点构建完后，可以构建no-left（支节点），用于保存的是leaf节点中的字符范围和指针信息；</span></p><p><span>④ 支节点构建完后，可以构建root（根节点），用于保存的是no-leaf节点中的字符范围和指针信息；</span></p><p><span>⑤ 找到相应辅助索引的数据信息后，在根据辅助索引与聚簇索引的对应关系，获取到相应的主键信息，从而获取相应其他数据信息</span></p><p><span>    在利用聚簇索引获取其他数据信息的过程，也可以称之为回表查询过程；</span></p><p>&nbsp;</p><p><strong><span>辅助索引检索数据产生回表问题分析：</span></strong><span>（回表次数越少越高）</span></p><p><span>产生问题：</span></p><p><span>① 在回表过程中，有可能会出现多次的回表，从而造成磁盘IOPS的升高；（因为是随机IO操作过程）</span></p><p><span>② 在回表过程中，有可能会出现多次的回表，从而造成磁盘IO量的增加；</span></p><p><span>解决方法：</span></p><p><span>① 可以建立联合索引，调整查询条件，使辅助索引过滤出更精细主键ID信息，从而减少回表查询的次数；</span></p><p><span>② 可以控制查询信息，实现覆盖索引，辅助索引完全覆盖查询结果；</span></p><p><span>③ 优化器算法做调整？？？(MRR-多路读功能 ICP-索引下推功能 )</span></p><p>&nbsp;</p><p><strong><span>构建索引树高度问题分析：</span></strong><span>（索引树高度越低越好）</span></p><p><span>影响索引树高度因素：</span></p><p><span>① 数据行数量会对高度产生影响；（3层BTREE -- 可以实现一般2000万行数据索引的存储-20~30列表）</span></p><p><span>    解决方法：可以拆分表 拆分库 或者实现分布式存储；</span></p><p><span>② 索引字段长度过大会对高度产生影响；</span></p><p><span>    解决方法：利用前缀索引解决问题</span></p><p><span>③ 数据类型设定会对高度产生影响；</span></p><p><span>    解决方法：列定义时，选择简短合适的数据类型；</span></p><h4><a name="1.7.4-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E5%BA%94%E7%94%A8%E6%96%B9%E6%B3%95" class="md-header-anchor"></a><span>1.7.4 数据库索引应用方法</span></h4><p><span>在进行索引操作之前，可以进行一个压力测试，将一个100W数据量的数据库备份数据进行备份恢复：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>10</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 进行测试数据恢复操作：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; source ~/t100w_oldboy.sql</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 进行数据库程序服务压测：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysqlslap <span class="cm-error cm-tw-deleted">--defaults-file=/etc/my.cnf --</span>concurrency=100 <span class="cm-error cm-tw-deleted">--iterations=1 --</span>create-schema='oldboy' <span class="cm-error cm-tw-deleted">--query="select * from oldboy.t100w where k2='VWlm'" engine=innodb --</span>number-of-queries=2000 -uroot -p123456 -h192.168.30.101 -verbose</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- concurrency=100  模拟同时100会话连接；</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- iterations=1 测试执行的迭代次数，代表要在不同并发环境下，各自运行测试多少次</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- create-schema='test'  指定操作的数据库信息；</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- query="select * from test.100w where k2='780P'"  指定压测过程具体执行了什么语句操作</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- number-of-queries=2000 指定一共做了多少次查询，总的测试查询次数(并发客户数×每客户查询次数)</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 432px;"></div><div class="CodeMirror-gutters" style="height: 432px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p><span>数据库压力测试结果情况：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668098473569.png' alt='1668098473569' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>进行索引建立优化：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> oldboy<span class="cm-variable-2">.t</span><span class="cm-number">100</span>w add index idx_k2(k2);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>在进行压测检查确认：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668098811913.png' alt='1668098811913' referrerPolicy='no-referrer' /></p><h5><a name="01-%E7%B4%A2%E5%BC%95%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C%E8%AF%B4%E6%98%8E%EF%BC%9A" class="md-header-anchor"></a><span>01 索引基本操作说明：</span></h5><p><strong><span>查询索引信息：</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; use world;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> city;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 查询表结构信息，获取索引配置</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668096887816.png' alt='1668096887816' referrerPolicy='no-referrer' /></p><p><span>索引信息的展示形式：</span></p><figure><table><thead><tr><th><span>序号</span></th><th><span>索引标识</span></th><th><span>解释说明</span></th></tr></thead><tbody><tr><td><span>01</span></td><td><span>PK（PRI）</span></td><td><span>表示为聚簇索引，也可以理解为主键索引</span></td></tr><tr><td><span>02</span></td><td><span>K（MUL）</span></td><td><span>表示为辅助索引，也可以理解为一般索引</span></td></tr><tr><td><span>03</span></td><td><span>UK</span></td><td><span>表示唯一键索引</span></td></tr></tbody></table></figure><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; use world;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show index <span class="cm-keyword">from</span> city;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 查询表索引信息，获取索引详细信息</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668097248110.png' alt='1668097248110' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>创建索引信息：</span></strong></p><p><span>创建单列索引方法：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">ALTER</span> <span class="cm-keyword">TABLE</span> `table_name` ADD PRIMARY KEY ( `column` )</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 创建主键索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city add index idx_name(name);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 创建辅助索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">ALTER</span> <span class="cm-keyword">TABLE</span> `table_name` ADD UNIQUE (`column`)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 创建唯一键索引</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 216px;"></div><div class="CodeMirror-gutters" style="height: 216px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668097623098.png' alt='1668097623098' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>创建联合索引方法：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city add index ix_na_po(name,population);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><span>创建前缀索引方法：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city add index ix_n(name(<span class="cm-number">10</span>));</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668098233152.png' alt='1668098233152' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>删除索引信息：</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="SQL"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>13</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 删除索引信息（一般索引）</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> 表名 <span class="cm-keyword">drop</span> index 索引名; &nbsp;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w <span class="cm-keyword">drop</span> index idx_name; &nbsp;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 删除辅助索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w <span class="cm-keyword">drop</span> index oldboy; &nbsp; &nbsp;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 删除联合索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w <span class="cm-keyword">drop</span> index id; &nbsp; &nbsp; &nbsp; &nbsp;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 删除唯一索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 删除索引信息（聚簇索引）</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> 表名 <span class="cm-keyword">drop</span> primary key;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w <span class="cm-keyword">drop</span> primary key; &nbsp; &nbsp; </span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 删除聚簇索引</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 468px;"></div><div class="CodeMirror-gutters" style="height: 468px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668097862043.png' alt='1668097862043' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><h3><a name="1.08-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92" class="md-header-anchor"></a><span>1.08 数据库服务执行计划</span></h3><h4><a name="1.8.1-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92%E6%A6%82%E5%BF%B5" class="md-header-anchor"></a><span>1.8.1 数据库执行计划概念</span></h4><ul><li><strong><span>执行计划介绍：</span></strong></li></ul><p><span>在介绍数据库服务程序运行逻辑时，在SQL层处理SQL语句时，会根据解析器生成解析树（多种处理方案）；</span></p><p><span>然后在利用优化器生成最终的执行计划，然后在根据最优的执行计划进行执行SQL语句；</span></p><p><span>作为管理员，可以在某个语句执行前，将语句对应的执行计划提取出来进行分析，便可大体判断语句的执行行为，从而了解执行效果；</span></p><p><code>可以简单理解：执行计划就是最优的一种执行SQL语句的方案，表示相应SQL语句是如何完成的数据查询与过滤，以及获取；</code></p><h4><a name="1.8.2-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92%E8%8E%B7%E5%8F%96" class="md-header-anchor"></a><span>1.8.2 数据库执行计划获取</span></h4><p><span>可以利用命令进行获取执行计划信息：explain/desc</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="SQL"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> explain <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> oldboy<span class="cm-variable-2">.t</span><span class="cm-number">100</span>w <span class="cm-keyword">where</span> k2=<span class="cm-string">'VWlm'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> 或者</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> oldboy<span class="cm-variable-2">.t</span><span class="cm-number">100</span>w <span class="cm-keyword">where</span> k2=<span class="cm-string">'VWlm'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>命令执行输出信息：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668100222339.png' alt='1668100222339' referrerPolicy='no-referrer' /></p><p><span>输出信息解释说明：</span></p><figure><table><thead><tr><th><span>序号</span></th><th><span>字段</span></th><th><span>解释说明</span></th></tr></thead><tbody><tr><td><span>01列</span></td><td><span>ID</span></td><td><span>表示语句执行顺序，单表查询就是一行执行计划，多表查询就会多行执行计划；</span></td></tr><tr><td><span>02列</span></td><td><span>select_type</span></td><td><span>表示语句查询类型，sipmle表示简单(普通)查询</span></td></tr><tr><td><span>03列</span></td><td><code>table</code></td><td><span>表示语句针对的表，单表查询就是一张表，多表查询显示多张表；</span></td></tr><tr><td><span>05列</span></td><td><code>type***</code></td><td><span>表示索引应用类型，通过类型可以判断有没有用索引，其次判断有没有更好的使用索引</span></td></tr><tr><td><span>06列</span></td><td><code>possible_keys</code></td><td><span>表示可能使用到的索引信息，因为列信息是可以属于多个索引的</span></td></tr><tr><td><span>07列</span></td><td><code>key</code></td><td><span>表示确认使用到的索引信息</span></td></tr><tr><td><span>08列</span></td><td><code>key_len***</code></td><td><span>表示索引覆盖长度，对联合索引是否都应用做判断</span></td></tr><tr><td><span>10列</span></td><td><code>rows</code></td><td><span>表示查询扫描的数据行数（尽量越少越好），尽量和结果集行数匹配，从而使查询代价降低</span></td></tr><tr><td><span>11列</span></td><td><span>fltered</span></td><td><span>表示查询的匹配度</span></td></tr><tr><td><span>12列</span></td><td><code>Extra***</code></td><td><span>表示额外的情况或额外的信息</span></td></tr></tbody></table></figure><h4><a name="1.8.3-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E5%BA%94%E7%94%A8%E7%B1%BB%E5%9E%8B" class="md-header-anchor"></a><span>1.8.3 数据库索引应用类型</span></h4><p><span>利用类型信息，来判断确认索引的扫描方式，常见的索引扫描方式类型：</span></p><figure><table><thead><tr><th><span>序号</span></th><th><span>类型</span></th><th><span>解释说明</span></th></tr></thead><tbody><tr><td><span>01</span></td><td><span>ALL - ok</span></td><td><span>表示全表扫描方式，没用利用索引扫描类型；</span></td></tr><tr><td><span>02</span></td><td><span>index</span></td><td><span>表示全索引扫描方式，需要将索引树全部遍历，才能获取查询的信息（主键index=全表扫描）</span></td></tr><tr><td><span>03</span></td><td><span>range</span></td><td><span>表示范围索引方式，按照索引的区域范围扫描数据，获取查询的数据信息；</span></td></tr><tr><td><span>04</span></td><td><span>ref</span></td><td><span>表示辅助索引等值（常量）查询，精准定义辅助索引的查询条件</span></td></tr><tr><td><span>05</span></td><td><span>eq_ref</span></td><td><span>表示多表连接查询时，被驱动表的连接条件是主键或者唯一键时，获取的数据信息过程；</span></td></tr><tr><td><span>06</span></td><td><span>const/system</span></td><td><span>表示主键或者唯一键等值（常量）查询，精准定义索引的查询条件</span></td></tr></tbody></table></figure><p>&nbsp;</p><p><strong><span>扫描类型执行计划展示效果：</span></strong></p><ul><li><strong><span>扫描类型-ALL：</span></strong></li></ul><p><span>此类型出现原因：查找条件没有索引；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668144613117.png' alt='1668144613117' referrerPolicy='no-referrer' /></p><p><span>此类型出现原因：查询条件不符合查询规律（like %%-只针对辅助索引，不影响主键索引-range）；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668144990799.png' alt='1668144990799' referrerPolicy='no-referrer' /></p><p><span>此类型出现原因：查询条件使用的了排除法（!=/not in-只针对辅助索引，不影响主键索引）；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668147150527.png' alt='1668147150527' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><ul><li><strong><span>扫描类型-index：</span></strong></li></ul><p><span>此类型出现原因：扫描查询列设置了辅助索引信息，但是没有基于索引列设置查询条件</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668145669313.png' alt='1668145669313' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><ul><li><strong><span>扫描类型-range：</span></strong></li></ul><p><span>此类型出现原因：查找条件是范围信息（&gt; &lt; &gt;= &lt;= between and in or）</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668146436653.png' alt='1668146436653' referrerPolicy='no-referrer' /></p><blockquote><p><span>特殊说明：在利用in查询数据信息时，查询效果和逻辑语句or的查询效果是一致；</span></p></blockquote><p><span>此类型出现原因：查找条件是模糊信息（like）</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668146518579.png' alt='1668146518579' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><ul><li><strong><span>扫描类型-ref：</span></strong></li></ul><p><span>此类型出现原因：查找条件是精确等值信息</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668168469509.png' alt='1668168469509' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><ul><li><strong><span>扫描类型-eq_ref：</span></strong></li></ul><p><span>此类型出现原因：被驱动表的链表条件是主键或唯一键时</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668184836060.png' alt='1668184836060' referrerPolicy='no-referrer' /></p><p><span>当连接查询没有where条件时：</span></p><p><span>左连接查询时，前面的表是驱动表，后面的表是被驱动表，右连接查询时相反；</span></p><p><span>内连接查询时，哪张表的数据较少，哪张表就是驱动表</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668171780619.png' alt='1668171780619' referrerPolicy='no-referrer' /></p><p><span>当连接查询有where条件时，带where条件的表是驱动表，否则是被驱动表</span></p><blockquote><p><span>说明：在没有设置比较合理索引情况下，默认选择结果集小的作为驱动表，即小表驱动大表；</span></p></blockquote><p><span>但是，此时如果给city表中的population加上索引信息，查找数据的执行计划才是最优的，对应获取数据的性能是最好的；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668172919364.png' alt='1668172919364' referrerPolicy='no-referrer' /></p><p><span>MySQL驱动表和被驱动表说明：</span><a href='https://www.cnblogs.com/oldboy666/p/16892774.html' target='_blank' class='url'>https://www.cnblogs.com/oldboy666/p/16892774.html</a></p><p>&nbsp;</p><ul><li><strong><span>扫描类型-const：</span></strong></li></ul><p><span>此类型出现原因：查询的数据条件是主键或唯一键，并且是精确等值查询；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668185588241.png' alt='1668185588241' referrerPolicy='no-referrer' /></p><h4><a name="1.8.4-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E8%A6%86%E7%9B%96%E9%95%BF%E5%BA%A6" class="md-header-anchor"></a><span>1.8.4 数据库索引覆盖长度</span></h4><p><span>在执行计划列中，key_len主要用来判断联合索引覆盖长度（字节），当覆盖长度越长，就表示匹配度更高，回表查询的次数越少；</span></p><p><span>到底联合索引被覆盖了多少，是可以通过key_len计算出来；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="SQL"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 联合索引设置</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t1 add index id_a_b_c(a列,b列,c列);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 联合索引应用</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t1 <span class="cm-keyword">where</span> a=xx <span class="cm-keyword">and</span> b=xx <span class="cm-keyword">and</span> c=xx</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-number">100</span>行 <span class="cm-comment">-- 回表100</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-number">50</span>行 &nbsp;<span class="cm-comment">-- 回表50</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-number">10</span>行 &nbsp;<span class="cm-comment">-- 回表10</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 252px;"></div><div class="CodeMirror-gutters" style="height: 252px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>如果全部覆盖到了：长度=a+b+c  即三个列最大预留长度的总和</span></p><p><span>最大预留长度影响因素？</span></p><ul><li><span>数据类型： </span></li><li><span>字符集（GBK：中文每个字符占用2个字节，英文1个字节 /UTF-8：中文每个字符占用3个字节，英文1个字节）</span></li><li><span>not null 是否可以为空    name  </span></li></ul><p><span>最大预留长度计算结果：不同的数据类型</span></p><figure><table><thead><tr><th><span>字段</span></th><th><span>数据类型</span></th><th><span>字符集</span></th><th><span>计算结果</span></th></tr></thead><tbody><tr><td><span>name</span></td><td><span>char(10)</span></td><td><span>utf8mb4</span></td><td><span>最大预留长度=4*10=40  10</span></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td><span>utf8</span></td><td><span>最大预留长度=3*10=30</span></td></tr><tr><td>&nbsp;</td><td><span>varcher(10)</span></td><td><span>utf8mb4</span></td><td><span>最大预留长度=4*10=40  + 2字节 =42    (1-2字节存储字符长度信息)  </span></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td><span>utf8</span></td><td><span>最大预留长度=3*10=30  + 2字节 =32     (1-2字节存储字符长度信息)</span></td></tr><tr><td>&nbsp;</td><td><span>tinyint</span></td><td><span>N/A</span></td><td><span>最大预留长度=1（大约3位数） 2的8次方=256</span></td></tr><tr><td>&nbsp;</td><td><span>int</span></td><td><span>N/A</span></td><td><span>最大预留长度=4（大约10位数） 2的32次方=4294967296</span></td></tr><tr><td>&nbsp;</td><td><span>bigint</span></td><td><span>N/A</span></td><td><span>最大预留长度=8（大约20位数)   2的64次方=18446744073709551616</span></td></tr><tr><td>&nbsp;</td><td><span>not null</span></td><td><span>N/A</span></td><td><span>在没有设置not null时，在以上情况计算结果再+1</span></td></tr></tbody></table></figure><p>&nbsp;</p><p><strong><span>实例操作练习：理解key_len索引覆盖长度</span></strong></p><p><span>创建一个测试数据表：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>12</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 常见测试数据表</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">use test;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">create</span> <span class="cm-keyword">table</span> keylen (</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  id <span class="cm-builtin">int</span> <span class="cm-keyword">not</span> <span class="cm-atom">null</span> primary key auto_increment,</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  k1 <span class="cm-builtin">int</span> <span class="cm-keyword">not</span> <span class="cm-atom">null</span>, &nbsp; &nbsp;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  k2 <span class="cm-builtin">char</span>(<span class="cm-number">20</span>), &nbsp; &nbsp; &nbsp; &nbsp; </span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  k3 <span class="cm-builtin">varchar</span>(<span class="cm-number">30</span>) <span class="cm-keyword">not</span> <span class="cm-atom">null</span>, &nbsp; </span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  k4 <span class="cm-builtin">varchar</span>(<span class="cm-number">10</span>) &nbsp; &nbsp; </span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">) charset=utf8mb4;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 设置表中列索引信息</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> keylen add index idx(k1,k2,k3,k4);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 432px;"></div><div class="CodeMirror-gutters" style="height: 432px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p><span>进行表结构信息与索引设置信息查询：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668190645162.png' alt='1668190645162' referrerPolicy='no-referrer' /></p><p><span>当四个索引信息全部覆盖，key_len数值计算结果：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>9</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># key_len计算思路</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">k1 = 4</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">k2 = 4 * 20 +1 = 81</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">k3 = 4 * 30 +2 = 122</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">k4 = 4 * 10 +2 + 1 = 43</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">sum = 4 + 81 + 122 + 43 = 250</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 进行校验结果</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">desc select * from keylen where k1=1 and k2='a' and k3='a' and k4='a';</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 324px;"></div><div class="CodeMirror-gutters" style="height: 324px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668191755129.png' alt='1668191755129' referrerPolicy='no-referrer' /></p><blockquote><p><span>说明：根据key_len长度数值，理想上是和联合索引的最大预留长度越匹配越好，表示索引都用上了，回表次数自然会少；</span></p></blockquote><h4><a name="1.8.5-%E6%95%B0%E6%8D%AE%E5%BA%93%E8%81%94%E5%90%88%E7%B4%A2%E5%BC%95%E5%BA%94%E7%94%A8" class="md-header-anchor"></a><span>1.8.5 数据库联合索引应用</span></h4><p><span>联合索引可以优化表中多列信息的查询，当需要多列信息查询时最好应用联合索引，不要应用多个单列索引；</span></p><p><span>在进行联合索引应用设置时，也是需要满足一定规范要求的，即使建立的联合索引，可能某些情况下，联合索引也不能大部分被使用；</span></p><p><span>因此，建立了联合索引，肯定是希望联合索引走的越多越好，但也有可能联合索引建立存在问题，也会导致查询效率较低；</span></p><p><strong><span>联合索引建立异常分析思路：</span></strong><span>   创建好联合索引 +  合理应用联合索引  发挥联合索引最大价值</span></p><ul><li><span>联合索引建立没有问题，但是查询语句书写有问题，导致联合索引应用效果不好；</span></li><li><span>查询语句书写没有问题，但是联合索引建立有问题，导致数据查询结果性能过低；</span></li></ul><p><strong><span>联合索引应用要遵循最左原则：</span></strong><span>（</span><code>以索引讲解表格进行说明最左原则</code><span>）</span></p><ul><li><span>建立索引的时候，最左列使用选择度高（cardinality-重复值少的列/唯一值多的列）的列</span></li><li><span>执行查询的时候，一定包含索引的最左条件；</span></li></ul><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668225766373.png' alt='1668225766373' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>应用情况一：联合索引全部覆盖：</span></strong></p><ul><li><span>需要满足最左原则；（尽量）</span></li><li><span>需要定义条件信息时，将所有联合索引条件都引用；（必要）</span></li></ul><p>&nbsp;</p><p><span>进行实战测试环境练习，属于联合索引全覆盖情况：</span></p><p><strong><span>实战测试01-步骤一：删除默认索引</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; use oldboy;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show index <span class="cm-keyword">from</span> t100w;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w <span class="cm-keyword">drop</span> index idx_k2;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show index <span class="cm-keyword">from</span> t100w;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> t100w;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 删除原有表中所有索引信息；</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 216px;"></div><div class="CodeMirror-gutters" style="height: 216px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668226447932.png' alt='1668226447932' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>实战测试01-步骤二：创建测试环境</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 在不满足最左原则创建联合索引</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> t100w add index idx(num,k1,k2);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 此时key_len的最大预留长度：4+1 + 2*4+1 + 4*4+1 = 31</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>联合索引创建情况：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668227060609.png' alt='1668227060609' referrerPolicy='no-referrer' /></p><p><span>验证索引全覆盖最大预留长度</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">913759</span> <span class="cm-keyword">and</span> k1=<span class="cm-string">'ej'</span> <span class="cm-keyword">and</span> k2=<span class="cm-string">'EFfg'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>最大预留长度验证结果：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668227311219.png' alt='1668227311219' referrerPolicy='no-referrer' /></p><blockquote><p><span>说明：进行联合索引全覆盖时，索引条件的应用顺序是无关的，因为优化器会自动优化索引查询条件应用顺序；</span></p></blockquote><p>&nbsp;</p><p><strong><span>实战测试02-步骤一：获取重复数据信息</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki" style="break-inside: unset;"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>29</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select num,count(*) from t100w group by num having count(*)&gt;1 order by count(*) desc limit 3;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------+----------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| num &nbsp;  | count(*) |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------+----------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| 339934 | &nbsp; &nbsp; &nbsp; 14 &nbsp;  |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| 614847 | &nbsp; &nbsp; &nbsp; 12 &nbsp;  |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  65003 | &nbsp; &nbsp; &nbsp; 12 &nbsp; &nbsp; |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------+----------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">3 rows in set (0.54 sec)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select * from t100w where num='339934';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+---------+--------+------+------+---------------------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| id &nbsp; &nbsp;  | num &nbsp;  | k1 &nbsp; | k2 &nbsp; | dt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+---------+--------+------+------+---------------------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  959036 | 339934 | 7X &nbsp; | jkwx | 2019-08-12 11:52:47 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| &nbsp;  4277 | 339934 | Ba &nbsp; | NOpq | 2019-08-12 11:41:21 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  185265 | 339934 | BO &nbsp; | 78Z0 | 2019-08-12 11:43:21 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  965745 | 339934 | eL &nbsp; | Z0wx | 2019-08-12 11:52:52 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  987825 | 339934 | fs &nbsp; | nomn | 2019-08-12 11:53:07 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  308385 | 339934 | g1 &nbsp; | deRS | 2019-08-12 11:44:44 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  223157 | 339934 | ku &nbsp; | mn89 | 2019-08-12 11:43:46 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  138236 | 339934 | or &nbsp; | UV45 | 2019-08-12 11:42:51 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  765105 | 339934 | rJ &nbsp; | 89qr | 2019-08-12 11:50:26 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  478517 | 339934 | t8 &nbsp; | abef | 2019-08-12 11:46:49 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  107745 | 339934 | tZ &nbsp; | noKL | 2019-08-12 11:42:31 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  503036 | 339934 | v3 &nbsp; | BCGH | 2019-08-12 11:47:07 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">|  596385 | 339934 | Yb &nbsp; | PQqr | 2019-08-12 11:48:17 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| 1000001 | 339934 | yb &nbsp; | pqqs | 2022-11-12 12:41:59 |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+---------+--------+------+------+---------------------+</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1044px;"></div><div class="CodeMirror-gutters" style="height: 1044px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>实战测试02-步骤二：插入新的测试数据</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">insert</span> <span class="cm-keyword">into</span> t100w <span class="cm-keyword">values</span>(<span class="cm-number">1000001</span>,<span class="cm-number">339934</span>,<span class="cm-string">'yb'</span>,<span class="cm-string">'pqqs'</span>,now());</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-string">'339934'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>实战测试02-步骤三：进行范围索引全覆盖查询</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span> <span class="cm-keyword">and</span> k1=<span class="cm-string">'yb'</span> <span class="cm-keyword">and</span> k2 &gt; <span class="cm-string">'PQqr'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> &nbsp;<span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span> <span class="cm-keyword">and</span> k1=<span class="cm-string">'yb'</span> <span class="cm-keyword">and</span> k2 &gt; <span class="cm-string">'PQqr'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>查询的结果信息：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668228959653.png' alt='1668228959653' referrerPolicy='no-referrer' /></p><blockquote><p><span>说明：在进行联合索引全覆盖查询时，</span><strong><code>最后一列</code></strong><span>不是精确匹配查询，而是采取区间范围查询，也可以实现索引全覆盖查询效果；</span></p></blockquote><p>&nbsp;</p><p><strong><span>应用情况二：联合索引部分覆盖：</span></strong></p><ul><li><span>需要满足最左原则；</span></li><li><span>需要定义条件信息时，将所有联合索引条件部分引用；</span></li></ul><p>&nbsp;</p><p><span>进行实战测试环境练习，属性联合索引部分覆盖情况：</span></p><p><strong><span>实战测试01-步骤一：进行部分查询测试</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>查询的结果信息：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668229326149.png' alt='1668229326149' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><strong><span>实战测试02-步骤一：临时关闭索引下推</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show variables <span class="cm-keyword">like</span> <span class="cm-string">'%switch%'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">set</span> global optimizer_switch=<span class="cm-string">'index_condition_pushdown=off'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 实现测试练习完，需要恢复开启（操作可以省略）</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>实战测试02-步骤二：进行部分列范围查询</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql &gt; <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span> <span class="cm-keyword">and</span> k1&lt;<span class="cm-string">'yb'</span> <span class="cm-keyword">and</span> k2=<span class="cm-string">'nokl'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql &gt; <span class="cm-keyword">desc</span> &nbsp;<span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span> <span class="cm-keyword">and</span> k1&lt;<span class="cm-string">'yb'</span> <span class="cm-keyword">and</span> k2=<span class="cm-string">'nokl'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>查询的结果信息：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668230013096.png' alt='1668230013096' referrerPolicy='no-referrer' /></p><blockquote><p><span>说明：进行联合索引覆盖查询时，区间范围列不是最后一列，索引查询匹配只统计到区间范围匹配(不等值)列，也属于部分覆盖；</span></p></blockquote><p>&nbsp;</p><p><strong><span>实战测试03-步骤一：进行部分查询测试</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num=<span class="cm-number">339934</span> &nbsp;<span class="cm-keyword">and</span> k2=<span class="cm-string">'ej'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>查询的结果信息：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668233771781.png' alt='1668233771781' referrerPolicy='no-referrer' /></p><blockquote><p><span>说明：进行联合索引覆盖查询时，查询索引列是不连续的，索引查询匹配只统计到缺失列前，也属于部分覆盖；</span></p></blockquote><p>&nbsp;</p><p><strong><span>应用情况三：联合索引完全不覆盖：</span></strong></p><ul><li><span>需要定义条件信息时，将所有联合索引条件都不做引用；</span></li></ul><p><span>进行实战测试环境练习，属性联合索引全不覆盖情况：</span></p><p><strong><span>实战测试01-步骤一：进行索引查询测试</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>实战测试02-步骤一：进行索引查询测试</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> num&lt;<span class="cm-number">339934</span> ;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><blockquote><p><span>说明：进行联合索引全不覆盖查询时，区间范围列出现在了第一列，也属于全不覆盖索引</span></p></blockquote><p>&nbsp;</p><p><strong><span>实战测试03-步骤一：进行索引查询测试</span></strong></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> t100w <span class="cm-keyword">where</span> k2=<span class="cm-string">'ej'</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 36px;"></div><div class="CodeMirror-gutters" style="height: 36px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><blockquote><p><span>说明：进行联合索引全不覆盖查询时，缺失最左列索引条件信息时，也属于全不覆盖索引</span></p></blockquote><p>&nbsp;</p><p><strong><span>联合索引最左原则压力测试：</span></strong></p><p><span>测试情况一：在不满足最左选择度高的情况；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>13</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 创建索引情况</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table t100w add index idx(num,k1,k2);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 执行压力测试命令</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">[root@xiaoQ-01 ~]</span># mysqlslap <span class="cm-error cm-tw-deleted">--defaults-file=/etc/my.cnf --</span>concurrency=100 <span class="cm-error cm-tw-deleted">--iterations=1 --</span>create-schema='oldboy' <span class="cm-error cm-tw-deleted">--query="select * from t100w where num=339934 and k1='yb' and k2='PQqr';" engine=innodb --</span>number-of-queries=200000 -uroot -p123456 -h192.168.30.101 -verbose</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysqlslap: <span class="cm-variable-3">[Warning]</span> Using a password on the command line interface can be insecure.</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Benchmark</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Running for engine rbose</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Average number of seconds to run all queries: 20.197 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Minimum number of seconds to run all queries: 20.197 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Maximum number of seconds to run all queries: 20.197 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Number of clients running queries: 100</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Average number of queries per client: 2000</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 540px;"></div><div class="CodeMirror-gutters" style="height: 540px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><p><span>测试情况二：在满足最左选择度高的情况；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki" style="break-inside: unset;"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>14</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 调整索引情况</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table t100w drop index idx;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table t100w add index idx(k1,k2,num);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 执行压力测试命令</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">[root@xiaoQ-01 ~]</span># mysqlslap <span class="cm-error cm-tw-deleted">--defaults-file=/etc/my.cnf --</span>concurrency=100 <span class="cm-error cm-tw-deleted">--iterations=1 --</span>create-schema='oldboy' <span class="cm-error cm-tw-deleted">--query="select * from t100w where num=339934 and k1='yb' and k2='PQqr';" engine=innodb --</span>number-of-queries=200000 -uroot -p123456 -h192.168.30.101 -verbose</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysqlslap: <span class="cm-variable-3">[Warning]</span> Using a password on the command line interface can be insecure.</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Benchmark</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Running for engine rbose</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Average number of seconds to run all queries: 20.494 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Minimum number of seconds to run all queries: 20.494 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Maximum number of seconds to run all queries: 20.494 seconds</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Number of clients running queries: 100</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  Average number of queries per client: 2000</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 576px;"></div><div class="CodeMirror-gutters" style="height: 576px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><h4><a name="1.8.6-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E6%89%A9%E5%B1%95%E4%BF%A1%E6%81%AF" class="md-header-anchor"></a><span>1.8.6 数据库索引扩展信息</span></h4><p><span>Extar列表示额外的情况或额外的信息说明，其中重点需要关注点信息为：filesort 表示涉及到额外排序操作，将严重浪费CPU资源；</span></p><p><strong><span>哪些查询语句情况涉及到排序操作：</span></strong><span>  </span></p><ul><li><span>情况一：查询语句中含有 order by ，表示触发式的排序；</span></li><li><span>情况二：查询语句中含有 group by，表示隐藏式的排序；</span></li><li><span>情况三：查询语句中含有 DISTINCT，表示会先进行排序后再取消重复；</span></li></ul><p>&nbsp;</p><p><strong><span>数据库查询出现排序情况演示说明</span></strong><span>：</span></p><p><span>进入到world数据库中，查看city索引信息设置，并将额外无用索引进行清理：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>9</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 查看指定表索引信息</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; use world;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show index <span class="cm-keyword">from</span> city;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 删除无用索引信息</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city <span class="cm-keyword">drop</span> index ix_na_po;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city <span class="cm-keyword">drop</span> index ix_n;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">alter</span> <span class="cm-keyword">table</span> city <span class="cm-keyword">drop</span> index idx;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 324px;"></div><div class="CodeMirror-gutters" style="height: 324px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>索引信息清理后，索引状态情况：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668243482553.png' alt='1668243482553' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>利用辅助索引信息作为条件，查看所有中国的城市情况信息：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> city <span class="cm-keyword">where</span> countrycode=<span class="cm-string">'CHN'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> city <span class="cm-keyword">where</span> countrycode=<span class="cm-string">'CHN'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 获取默认查询执行计划情况</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>在没有进行排序前的执行计划情况：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668243762945.png' alt='1668243762945' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>模拟出现查询数据的排序情况：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="SQL"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"># 模拟情况一：利用order <span class="cm-keyword">by</span>实现排序</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; <span class="cm-keyword">desc</span> <span class="cm-keyword">select</span> * <span class="cm-keyword">from</span> city <span class="cm-keyword">where</span> countrycode=<span class="cm-string">'CHN'</span> <span class="cm-keyword">order</span> <span class="cm-keyword">by</span> population;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>执行计划信息输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668243940742.png' alt='1668243940742' referrerPolicy='no-referrer' /></p><p><span>执行计划优化处理：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 错误设想创建索引：因为本身索引构建过程就存在自动排序问题</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">alter table city add index idx(population)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>实际效果信息输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668243940742.png' alt='1668243940742' referrerPolicy='no-referrer' /></p><p><span>没有改变最终的执行计划结果，因为在使用索引时，只能使用单一的索引树，不能跨越多颗索引树进行使用，因此优化失败；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 正确优化处理方式：创建联合索引</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table city add index idx1(countrycode,population);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>实际效果信息输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668267195060.png' alt='1668267195060' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>特殊情况说明：在order by信息出现在group by之后，是无法实现索引优化处理的</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>4</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 模拟情况二：利用group by实现排序</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; desc select district,count(*) from city where countrycode='CHN' group by district;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; desc select district,count(*) from city where countrycode='CHN' group by district order by sum(population);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 180px;"></div><div class="CodeMirror-gutters" style="height: 180px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>实际效果信息输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668267966104.png' alt='1668267966104' referrerPolicy='no-referrer' /></p><p><span>从上图执行计划输出信息可以看出，因为group by操作后，已经将数据信息存放在了临时表中，order by排序就不能再用索引了；</span></p><p>&nbsp;</p><h4><a name="1.8.7-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E5%BA%94%E7%94%A8%E6%80%BB%E7%BB%93" class="md-header-anchor"></a><span>1.8.7 数据库索引应用总结</span></h4><p><strong><span>01 建立索引原则规范（DBA运维规范）</span></strong></p><ul><li><span>数据表中必须要有主键索引（创建表时指定），建议是与业务无关的自增列；    </span></li><li><span>数据表中某些列若经常作为 where/order by/group by/join on/distinct条件信息，最好将相应列设置索引（产品功能/用户行为）</span></li><li><span>数据表中最好使用唯一值多的列作为索引，如果索引列重复值较多，可以考虑使用联合索引；（最左列-减少回表次数 - 减少磁盘IO）</span></li><li><span>数据表中列值长度较长的索引列，建议可以使用前缀索引；(防止索引树层次过高)</span></li><li><span>数据表中不建议建立大量索引，最好降低索引条目，不要创建无用索引，不常用的索引要定期清理（percona toolkit）  </span></li><li><span>数据表中的索引信息做调整维护时，尽量避开业务繁忙期，或者通过软件工具做调整维护（pt-ost）</span></li><li><span>数据表中的联合索引创建过程要遵循索引最左原则；</span></li></ul><p>&nbsp;</p><p><strong><span>02 索引应用失效情况（开发工作规范）</span></strong></p><ul><li><span>数据表信息查询时，没有设置查询条件信息；      </span></li><li><span>数据表信息查询时，查询的条件没有建立索引；   </span></li></ul><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select * from t1;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select * from t1 where id=1001 or 1=1; &nbsp; <span class="cm-error cm-tw-deleted">-- 执行SQL注入语句问题</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>03 查询结果规范要求</span></strong><span>    </span></p><p><span>当查询结果集数据是原表中的大部分数据，超过了总行数的25%，优化器便自动判断没必要走索引了，因为可以借助预读功能获取数据</span></p><p><span>可以通过精细查找指定数据的范围，从而达到优化的效果；（read_head预读相关参数）</span></p><p>&nbsp;</p><p><strong><span>04 索引失效情况处理</span></strong></p><p><span>当频繁的对数据表中索引列值做修改、删除等操作时，会导致索引统计信息过旧或不真实，最终造成索引功能失效；</span></p><p><span>本身索引是有自我维护的机制能力，但并不是实时调整更新的，需要有一定的间隔时间做调整；</span></p><p><span>一般索引失效的表现情况为：select查询语句平常查询时很快，但突然某天执行就变慢了，就是索引失效了，统计数据不真实；</span></p><p><span>索引统计的信息存储位置：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">innodb_index_stats</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">innodb_table_stats</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- mysql库中的相应表</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>当索引失效时，可以使用命令重新进行统计信息获取，使索引功能再次生效：</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql &gt; analyze <span class="cm-keyword">table</span> world<span class="cm-variable-2">.city</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">-- 表示立即更新过久的统计信息（也可以将索引删除重建）</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><p><span>在查询条件过程中，使用了函数信息在索引列上，或者对索引进行了运算（+ - * / ！等），都会导致索引功能失效，建议尽量避免；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki" style="break-inside: unset;"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>17</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 错误举例：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select * from test where id-1=9;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 正确举例：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select * from test where id=10;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 总之尽量避免条件信息出现 算数运算  函数运算  子查询</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 子查询补充：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 子查询指一个查询语句嵌套在另一个查询语句内部的查询</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># SQL 中子查询的使用大大增强了 SELECT 查询的能力，因为很多时候查询需要从结果集中获取数据</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 查询中国城市人口大于北京人口数量的城市信息</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">查询01：查询中国 北京的人口数量</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select population from city where countrycode='CHN' and name='Peking';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">查询02：查询中国 基于北京人口数量 大于北京人口数量城市</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">select * from city where countrycode='CHN'  and population &gt; 'xxx'</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select * from city where CountryCode='CHN' and population &gt; (select population from city where CountryCode='CHN' and name='Peking');</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 648px;"></div><div class="CodeMirror-gutters" style="height: 648px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><p><span>在查询数据信息过程中，出现了隐式转换也会导致索引失效；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 创建测试数据表</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; create table test (id int,name varchar(20),telno char(11));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; insert into test values (1,'a','110'),(2,'b','123'),(3,'c','120'),(4,'d','119'),(5,'e','130');</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 创建索引信息</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table test add index idx(telno);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 查询数据信息</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select * from test where telno='110';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select * from test where telno=110;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 上面两条语句都能查看到结果信息，但是有一条语句是没有走索引的</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 396px;"></div><div class="CodeMirror-gutters" style="height: 396px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p><span>执行计划结果输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668273476461.png' alt='1668273476461' referrerPolicy='no-referrer' /></p><p><span>因为本身查询条件列的数据类型为字符类型，但是作为条件时当成了数字类型，数据库会将数值类型通过隐式转换函数转换为字符类型；</span></p><p><span>由于，条件中若加上了函数信息，就会导致索引功能失效，所以隐式转换也会造成索引失效；</span></p><p>&nbsp;</p><p><span>在查询条件过程中，应用了特殊数据匹配方法时，也会导致索引失效，一般是辅助索引失效；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">&lt;&gt; , not in , like "%_" </span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 应用以上特殊符号信息，也会导致辅助索引失效</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><h4><a name="1.8.8-%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B4%A2%E5%BC%95%E7%9F%A5%E8%AF%86%E6%89%A9%E5%B1%95" class="md-header-anchor"></a><span>1.8.8 数据库索引知识扩展</span></h4><p><strong><span>01 数据库服务索引功能特性</span></strong></p><ul><li><span>在新的数据库服务中，支持不可见索引功能</span></li></ul><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>4</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 在创建索引或修改索引时，可以设置不可见或可见索引（默认）</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table test alter index idx invisible;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; alter table test add index idx1(name) invisible;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 在做批量数据导入时，辅助索引信息可以设置为不可见，优化器就不会加载识别索引信息</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 144px;"></div><div class="CodeMirror-gutters" style="height: 144px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>执行计划信息输出：</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1668275093450.png' alt='1668275093450' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><ul><li><span>在新的数据库服务中，支持倒序索引功能</span></li></ul><p><span>在早期数据库中，所有索引列创建索引信息，都是按照从小到大顺序进行排序，在最新数据库中，可以灵活调整索引排序方式；</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 官方解释说明</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">idx(a,b,c)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 创建a b c 索引列 并按照从小到大排序</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">desc select * from where xx order by a,b desc,c &nbsp; 索引全覆盖</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">order by a,b desc,c</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 由于排序中出现了逆向排序，所以只有a列会走索引，查询b和c还是会再进行排序处理，不会利用索引排序</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 最新版数据库索引创建</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">idx(a,b desc,c)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 可以灵活调整索引排序方式，应对不同的查询条件，从而避免排序问题对CPU资源的消耗</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 396px;"></div><div class="CodeMirror-gutters" style="height: 396px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><p><strong><span>02 数据库服务自主优化能力</span></strong></p><ul><li><strong><span>自主优化功能一：AHI（索引的索引）</span></strong></li></ul><p><span>AHI全称（中文名称）为自适应的hash索引/散列索引，用于在内存中建立索引，快速锁定内存中的热点数据索引页位置；</span></p><p><span>正常情况下，所有数据都是存储在磁盘中的，如果想访问读取相应磁盘的数据信息，都是会将磁盘数据调取存放在内存中，即消耗IO；</span></p><p><span>对于数据库服务而言，想要读取数据信息，也是会从磁盘中读取存储页，在放入内存中被数据库服务进行访问，索引访问也是一样的；</span></p><p><span>但是当数据页大量的被存放在内存中后，从大量内存中的数据页找到想要的，也是比较困难的事情；</span></p><p><span>因此，可以对内存中经常被访问数据索引页建立一个hash索引，从而可以帮助数据库服务快速定位内存中想要找的索引数据页；</span></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1675276929767.png' alt='1675276929767' referrerPolicy='no-referrer' /></p><p><span>AHI功能配置信息:</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show variables like 'innodb_adaptive_hash_index';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| Variable_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Value |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| innodb_adaptive_hash_index  | ON &nbsp;  |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+--------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">1 row in set (0.00 sec)</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 252px;"></div><div class="CodeMirror-gutters" style="height: 252px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p>&nbsp;</p><ul><li><strong><span>自主优化功能二：CHANGE BUFFER</span></strong></li></ul><p><span>早期版本称为 insert buffer，只是对插入操作有作用，版本更新后(5.6)，可以对插入 修改 删除操作都有作用效果；</span></p><p><span>change buffer主要是针对辅助索引的缓冲区，属于内存结构上的应用；</span></p><p><span>changerbuffer应用原理：假设现在需要插入一行数据信息</span></p><p><span>① 插入一行数据信息到表中，将会实时立即更新聚簇索引信息，因为利用聚簇索引是用来获取数据页上详细原表数据信息的；</span></p><p><span>② 插入一行数据信息到表中，不会实时立即更新辅助索引信息，因为利用辅助索引是用来获取索引页上聚簇索引数据信息的；</span></p><p><span>    如果此时实时更新了辅助索引的信息，有可能会导致出现数据页分裂，造成辅助索引树结构变化，形成索引树访问阻塞(锁机制)；</span></p><p><span>③ 为了避免辅助索引树结构变更，对数据库服务并发访问的影响，可以将插入的数据信息，暂时存储在缓冲区中；</span></p><p><span>    当利用辅助索引检索数据时，可以将检索到数据页范围信息调取到内存中，与缓存区数据进行合并，自然可以检索到插入的数据；</span></p><blockquote><p><span>说明：在数据表中插入 修改 删除数据时，聚簇索引树会进行同步实时更新，辅助索引树会进行异步延时更新。</span></p></blockquote><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1675277639034.png' alt='1675277639034' referrerPolicy='no-referrer' /></p><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1675278504422.png' alt='1675278504422' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p><span>change_buffer功能配置信息:</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>10</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show variables like '%change_buffer%';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+-----------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| Variable_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | Value |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+-----------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| innodb_change_buffer_max_size | 25 &nbsp;  |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">| innodb_change_buffering &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  | all &nbsp; |</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket">+-----------------------------------------+-------+</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">2 rows in set (0.00 sec)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">--all：<span class="cm-tab" role="presentation" cm-text="	">  </span>  默认值。开启buffer inserts、delete-marking operations、purges</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" class="cm-tab-wrap-hack" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">--none：<span class="cm-tab" role="presentation" cm-text="	"> </span>不开启change buffer</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 364px;"></div><div class="CodeMirror-gutters" style="height: 364px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><ul><li><strong><span>自主优化功能三：ICP （索引下推）</span></strong></li></ul><p><span>属于5.6之后引用的数据库服务新特性，称之为索引下推功能，主要是针对联合索引功能起作用；</span></p><p><span>ICP应用原理：假设创建联合索引进行数据检索</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>2</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">idx(a,b,c)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">where a=10 and b like '%x%' and c=z </span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 72px;"></div><div class="CodeMirror-gutters" style="height: 72px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><span>在没有ICP优化机制情况：</span></p><p><span>基于联合索引的特性，查找检索数据只会依据a进行检索，可能检索到的数据页是100个数据块，会将数据放入内存中；</span></p><p><span>数据信息到达内存中后，在根据b和c的条件信息进行定位最终的聚簇索引信息，进行回表查询；</span></p><blockquote><p><span>说明：基于数据库优化器的特性，遵循联合索引引用原则，SQL层面只能检索到联合索引中的A；</span></p></blockquote><p><span>在应用ICP优化机制情况：</span></p><p><span>基于联合索引的特性，查找检索数据只会依据a进行检索，但是b和c也属于联合索引中的索引部分，在SQL层不能再进行索引情况下；</span></p><p><span>可以将b和c的检索工作下推交给引擎层完成，可以让引擎再调取数据到内存之前，再根据b和c的条件进行一次过滤；</span></p><p><span>可以将过滤后的数据信息再放入到内存中，然后结合获取到的聚簇索引信息，进行回表查询；</span></p><blockquote><p><span>说明：基于数据库优化器的特性，可以将SQL层完成不了的检索工作，下推给引擎层完成，从而减少磁盘IO消耗，以及回表策略</span></p></blockquote><p>&nbsp;</p><p><span>ICP功能配置信息:</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="tiki wiki"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="tiki wiki"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 48px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 44px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -44px; width: 44px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; show variables like '%switch%';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; set global optimizer_switch='index_condition_pushdown=off';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- 实现测试练习完，需要恢复开启（操作可以省略）</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 测试练习</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; select * from t100w where k1='qj' and k2 like '%v%';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql&gt; desc select * from t100w where k1='qj' and k2 like '%v%';</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-error cm-tw-deleted">-- extra列显示using index condition信息，表示应用了索引下推</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tw-listitem cm-bracket"># 进行压测</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -44px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysqlslap <span class="cm-error cm-tw-deleted">--defaults-file=/etc/my.cnf --</span>concurrency=100 <span class="cm-error cm-tw-deleted">--iterations=1 --</span>create-schema='oldboy' <span class="cm-error cm-tw-deleted">--query="select * from t100w where k1='qj' and k2 like '%v%" engine=innodb --</span>number-of-queries=20000 -uroot -p123456 -h192.168.30.101 -verbose</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 468px;"></div><div class="CodeMirror-gutters" style="height: 468px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre><p>&nbsp;</p><ul><li><strong><span>自主优化功能四：MRR</span></strong></li></ul><p><span>MRR，全称（Multi-Range Read Optimization 多范围读取操作）；</span></p><p><code>简单来说：MRR 通过把「随机磁盘读」，转化为「顺序磁盘读」，从而提高了索引查询的性能。</code></p><p><span>描述说明中涉及到的问题：</span></p><p><span>① 为什么要把随机读转换为顺序读？  减少磁盘压力</span></p><p><span>② 为什么顺序读就能提升读取性能？   </span></p><p><span>③ 如何将随机读去转换为顺序读取？  MRR</span></p><p>&nbsp;</p><p><span>MRR功能配置信息:</span></p><pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="sql"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="sql"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 35px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 31px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -31px; width: 31px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql &gt; <span class="cm-keyword">set</span> optimizer_switch=<span class="cm-string">'mrr=on'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 23px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">mysql &gt; <span class="cm-keyword">set</span> global optimizer_switch=<span class="cm-string">'mrr_cost_based=off'</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -31px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 23px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Query OK, <span class="cm-number">0</span> rows affected (<span class="cm-number">0.06</span> sec)</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 108px;"></div><div class="CodeMirror-gutters" style="height: 108px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 31px;"></div></div></div></div></pre><p><img src='../../../../../../../../../%E6%8A%80%E6%9C%AF%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E6%96%87%E6%A1%A3/IT%E6%8A%80%E6%9C%AF%E5%9F%B9%E8%AE%AD%E8%B5%84%E6%96%99%E6%B1%87%E6%80%BB-%E8%BF%90%E7%BB%B4%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/01-%E8%BF%90%E7%BB%B4%E6%95%99%E8%82%B2%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99/%E3%80%90HQ%E6%95%99%E5%AD%A6%E8%B5%84%E6%96%99%E3%80%91lesson42-Linux%E6%95%B0%E6%8D%AE%E5%BA%93-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9E%84%E5%BB%BA%E4%B8%8E%E5%BA%94%E7%94%A8/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B%E8%B5%84%E6%96%99/%E8%AF%BE%E7%A8%8B%E6%95%99%E6%A1%88%E6%96%87%E6%A1%A3%E8%B5%84%E6%96%99/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E7%8F%AD%E8%AF%BE%E7%A8%8B_%E6%95%B0%E6%8D%AE%E5%BA%93%E6%9C%8D%E5%8A%A1%E6%90%AD%E5%BB%BA%E5%BA%94%E7%94%A8%E7%AB%A0%E8%8A%82-%E6%95%99%E6%A1%88%E8%B5%84%E6%96%99%E5%BA%93/Linux%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4%E8%AF%BE%E7%A8%8B-%E6%9E%B6%E6%9E%84%E6%9C%8D%E5%8A%A1%E7%AB%A0%E8%8A%82-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E8%AF%BE%E7%A8%8B%E7%AC%94%E8%AE%B0/1675369639191.png' alt='1675369639191' referrerPolicy='no-referrer' /></p><p>&nbsp;</p><p>&nbsp;</p></div>
</body>
</html>